package mobi.hami.huapin.service.impl;

import mobi.hami.huapin.dao.HpEnterLogMapper;
import mobi.hami.huapin.dao.HpShareLogMapper;
import mobi.hami.huapin.model.HpEnterLog;
import mobi.hami.huapin.model.HpShareLog;
import mobi.hami.huapin.service.HpShareLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * 类说明
 *
 * @author 阿飞 jijunjian@hami.mobi
 * @date 10/8/2018 8:40 PM
 */
@Service
public class HpShareLogServiceImpl implements HpShareLogService {

    @Autowired
    HpEnterLogMapper enterLogMapper;
    @Autowired
    HpShareLogMapper shareLogMapper;

    /**
     * 分享
     *
     * @param reqMap
     * @return
     */
    @Override
    public int share(Map<String, String> reqMap) {

        HpShareLog log = new HpShareLog();
        log.setFrom_page(reqMap.get("from_page"));
        log.setFrom_tag( Integer.parseInt(reqMap.get("from_tag")));
        log.setGmt_create(new Date());
        log.setShare_user_id(reqMap.get("share_user_id"));
        log.setSn(reqMap.get("sn"));
        shareLogMapper.insertSelective(log);

        return 1;
    }

    /**
     * 从分享进入
     *
     * @param reqMap
     * @return
     */
    @Override
    public int enterFromShare(Map<String, String> reqMap) {
        if(reqMap==null || reqMap.isEmpty()){
            return 0;
        }
        HpEnterLog enterLog = new HpEnterLog();
        enterLog.setSn(reqMap.get("sn")==null?"":reqMap.get("sn"));
        enterLog.setGmt_create(new Date());
        enterLog.setUser_id(Long.parseLong(reqMap.get("user_id")==null?"0":reqMap.get("user_id")));
        enterLogMapper.insertSelective(enterLog);
        return 1;
    }
}
